Skip to content

bench: add experimental node:bench module - #65606

Open
jasnell wants to merge 6 commits into
nodejs:mainfrom
jasnell:jasnell/node-bench
Open

bench: add experimental node:bench module#65606
jasnell wants to merge 6 commits into
nodejs:mainfrom
jasnell:jasnell/node-bench

Conversation

@jasnell

@jasnell jasnell commented Aug 28, 2026

Copy link
Copy Markdown
Member

A new node:bench module, modeled closely after the node:test architecture.

import { bench, suite } from 'node:bench';

suite('URL', () => {
  const input = 'https://example.com/a?b=c';

  bench('construct', {
    samples: 30,
    params: { input: 'short' },
  }, (b) => {
    const operations = 10_000;

    b.start();
    for (let i = 0; i < operations; i++) {
      new URL(input);
    }
    b.end(operations);
  });
});
node --bench benchmark.mjs

The core functionality is here but there are still improvements that are needed. Specifically, there's a fair amount of overhead interjected by the harness itself that can impact the results. The focus was on minimal functionality, not absolutely optimal functionality. But this gives a solid starting point for improvements.

Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
Signed-off-by: James M Snel <jasnell@gmail.com>
Assisted-by: Opencode
@jasnell
jasnell requested a review from mcollina August 28, 2026 01:24
@jasnell jasnell added semver-minor PRs that contain new features and should be released in the next minor version. experimental Issues and PRs related to experimental features. labels Aug 28, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/performance
  • @nodejs/startup
  • @nodejs/tsc

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Aug 28, 2026
@jasnell jasnell added performance Issues and PRs related to the performance of Node.js. large-pr PRs subject to the large-PR policy. and removed lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Aug 28, 2026
Signed-off-by: James M Snell <jasnell@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.38845% with 174 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.09%. Comparing base (05a8e91) to head (9176490).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/bench_runner/cli.js 88.18% 72 Missing and 3 partials ⚠️
lib/internal/bench_runner/harness.js 93.90% 42 Missing and 1 partial ⚠️
lib/internal/bench_runner/benchmark.js 93.91% 25 Missing ⚠️
lib/internal/bench_runner/reporter/spec.js 92.61% 10 Missing and 1 partial ⚠️
src/node_options.cc 75.00% 7 Missing and 3 partials ⚠️
lib/internal/bench_runner/reporter/json.js 92.18% 4 Missing and 1 partial ⚠️
src/histogram.cc 93.61% 0 Missing and 3 partials ⚠️
src/node_options-inl.h 85.71% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65606      +/-   ##
==========================================
+ Coverage   90.06%   90.09%   +0.02%     
==========================================
  Files         751      761      +10     
  Lines      254919   257177    +2258     
  Branches    48124    48613     +489     
==========================================
+ Hits       229603   231697    +2094     
- Misses      16492    16649     +157     
- Partials     8824     8831       +7     
Files with missing lines Coverage Δ
lib/bench.js 100.00% <100.00%> (ø)
lib/bench/reporters.js 100.00% <100.00%> (ø)
lib/internal/bench_runner/benchmarks_stream.js 100.00% <100.00%> (ø)
lib/internal/bench_runner/runner.js 100.00% <100.00%> (ø)
lib/internal/bootstrap/realm.js 96.31% <100.00%> (+0.01%) ⬆️
lib/internal/histogram.js 96.22% <100.00%> (+0.11%) ⬆️
lib/internal/main/bench_runner.js 100.00% <100.00%> (ø)
src/histogram.h 72.72% <ø> (ø)
src/node.cc 76.61% <100.00%> (+0.06%) ⬆️
src/node_config_file.cc 83.68% <ø> (ø)
... and 9 more

... and 44 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

experimental Issues and PRs related to experimental features. large-pr PRs subject to the large-PR policy. performance Issues and PRs related to the performance of Node.js. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants